using System;
using System.ComponentModel;
using System.Data;
using System.Collections.Generic;

namespace PlacementManager
{
    public partial class LinkStudentUnitComponent
    {
		//
		// TODO: Add constructor logic here
		//

        /// <summary>
        /// Unenrols the student from associated units.
        /// </summary>
        /// <param name="o">An object of a datatype representing a row in the database table.</param>
        /// <returns>Boolean</returns>

        public bool UnEnrolWUsername(string userName)
        {
            PlacementManager.DAL.LinkStudentUnit_DAL oLinkStudentUnit = new PlacementManager.DAL.LinkStudentUnit_DAL();

            oLinkStudentUnit.UserName = userName;
            return oLinkStudentUnit.UnEnrolWUsername();
        }

        /// <summary>
        /// Selects all records from the database table based on a foreign key.
        /// </summary>
        /// <returns>A collection of objects of a type representing a row in the database table.</returns>
        [DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
        public List<LinkStudentUnit> SelectAllWUnitIdUsername(int UnitId,string userName, string sortExpression)
        {
            List<LinkStudentUnit> listLinkStudentUnit = new List<LinkStudentUnit>();
            PlacementManager.DAL.LinkStudentUnit_DAL o = new PlacementManager.DAL.LinkStudentUnit_DAL();
            o.UnitId = UnitId;
            o.UserName = userName;
            DataSet ds = o.SelectAllWUnitIdUsername();
            foreach (DataRow row in ds.Tables[0].Rows)
            {
                listLinkStudentUnit.Add(new LinkStudentUnit((int)row["StudentUnitId"], (string)row["UserName"], (int)row["UnitId"], (bool)row["IsCurrentlyEnrolled"], (bool)row["IsActive"], (DateTime)row["DateCreated"], (string)row["CreatedBy"], (DateTime)row["DateUpdated"], (string)row["UpdatedBy"]));
            }
            if (sortExpression == string.Empty)
            {
                sortExpression = "DateCreated desc";
            }
            listLinkStudentUnit.Sort(new LinkStudentUnitComparer(sortExpression));
            return listLinkStudentUnit;
        }
	}
}
